Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse cube-finder-db.db and include MPNs in output #6

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ubruhin
Copy link
Member

@ubruhin ubruhin commented Sep 1, 2023

I saw that in the STM32 database directory there's also an SQLite database including the exact MPNs for all MCUs. Since the MPNs are now useful for LibrePCB (to export accurate BOMs), I extended the script to also extract that data from this database and include it in the generated JSON files.

Example output (new node parts):

{
  "names": {
    "name": "STM32C011D6Yx",
    "ref": "STM32C011D6Yx",
    "family": "STM32C0",
    "line": "STM32C0x1",
    "rpn": "STM32C011D6"
  },
  "package": "WLCSP12",
  "silicon": {
    "core": "ARM Cortex-M0+",
    "die": "DIE443"
  },
  "info": {
    "flash": 32,
    "ram": 6,
    "io": 10,
    "frequency": 48,
    "voltage": {
      "min": 2.0,
      "max": 3.6
    },
    "temperature": {
      "min": -40.0,
      "max": 85.0
    }
  },
  "parts": [
    {
      "mpn": "STM32C011D6Y6TR",
      "temperature_min": -40.0,
      "temperature_max": 85.0,
      "packing_type": "Tape and Reel",
      "status": "Active"
    },
    {
      "mpn": "STM32C011D6Y3TR",
      "temperature_min": -40.0,
      "temperature_max": 125.0,
      "packing_type": "Tape and Reel",
      "status": "Coming soon"
    }
  ],
  "gpio_version": "STM32C0xx_gpio_v1_0",
  /* ... */
}

Note that the temperature min/max are now redundant in the output files, but it makes sense to have them in the parts section because they may be different for the different MPNs. We might consider removing them from the outer node now...

In addition, there are actually many more attributes stored in the database but for now I extracted only 5 of them which are most useful for LibrePCB. One might argue that we should include all existing data into the JSON files(?)

Regarding license, probably it doesn't make a difference whether we fetch data from an XML file or from an SQLite database so I suspect this change does not affect the license situation of our generated parts.

TODO:

  • Check if STM8CubeMX provides this database as well and re-generate STM8 files.
  • As many existing JSON files have been modified because of using the latest STM32CubeMX, there's some risk of breaking LibrePCB library elements. We should check somehow if this is the case. But this might be a task for librepcb-parts-generator since this repository is just responsible for putting data from ST into a useful format...

/cc @dbrgn

Copy link
Member

@dbrgn dbrgn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool! Extracting MPNs is something I already thought of when writing this extractor. Great to see that it can now be used!

Comment on lines +67 to +77
res = self._cur.execute(
"SELECT strValue, numValue FROM cpn_has_attribute "
"LEFT JOIN attribute "
"ON attribute.id = cpn_has_attribute.attribute_id "
"WHERE cpn_id = :cpn_id "
"AND attribute.name = :attribute_name",
dict(
cpn_id=cpn_id,
attribute_name=attribute_name,
),
).fetchone()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be a multi-line string for easier readability:

        res = self._cur.execute("""
            SELECT strValue, numValue FROM cpn_has_attribute
            LEFT JOIN attribute
            ON attribute.id = cpn_has_attribute.attribute_id
            WHERE cpn_id = :cpn_id
            AND attribute.name = :attribute_name
            """,
            dict(
                cpn_id=cpn_id,
                attribute_name=attribute_name,
            ),
        ).fetchone()

"temperature_min": -40.0,
"temperature_max": 125.0,
"packing_type": "Tape and Reel",
"status": "Coming soon"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably ignore or re-map "Coming soon" parts. But that's a choice for the parts generator.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was exactly my intention! 😃 In addition, for the non-skipped MPNs I'd also add this status information as an attribute to the parts because the status "NRND" is then directly visible in the component picker dialog.

But as you said, this is the decision of the parts generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants